<?php
class Upload extends CI_Controller{
	public function __construct(){
		parent::__construct();
		$this->load->helper(array("url","form"));
	}
	public function index(){
	//	$this->load->view("upload_view");
	}
	
	public function files(){
		//$this->load->model("backend/mupload");
		//$data['files'] = $this->mupload->get_all_files();
		//$this->load->view("files",$data);
	}
	
	public function upload_file(){
			$status = "";
			$msg = "";
			$tit = $this->input->post("full_name");
			if($tit == NULL){
				$status = "error";
				$msg = "Please enter your full_name";	
			}
			if($status != "error"){
				$config['upload_path'] = '.\upload';
				$config['allowed_types'] = 'gif|jpg|png|doc|txt|mp4|flv|FLV';
				$config['max_size']  = 10000024 * 8;
				$config['encrypt_name'] = TRUE;
				set_time_limit(600);
				$this->load->library("upload",$config);
				if(!$this->upload->do_upload("ufile")){
					$status = "error";
					$msg = $this->upload->display_errors('<p>','</p>');
					echo $msg;
				}else{
					$this->load->model("backend/mupload");
					$data = $this->upload->data();
					$info = array("video_project" => $data['file_name'],
								  "name_project"     => $_POST['full_name']);
					$fid = $this->mupload->insert_file($info);
					if($fid){
						$status = "Success";
						$msg = "File successfully uploaded";	
					}else{
						$status = "error";
						$msg = "File uploaded fail! PLease try again!"; 	
					}
				}
			}
			echo json_encode(array("status"    => $status,
								   "msg"   => $msg));
	}
	
	public function delete_files($file_id){
		$this->load->model("backend/mupload");
		if($this->mupload->delete_file($file_id)){
			$status = 'success';
     		$msg = 'File successfully deleted';
		}else{
			$status = 'error';
     		$msg = 'Something went wrong when deleteing the file, please try again';
		}
		echo json_encode(array('status' => $status, 'msg' => $msg));
	}
	
	

}